package com.zzl.finance.order.controller;

import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.finance.order.dto.OrderAddDto;
import com.zzl.finance.order.dto.OrderUpdateDto;
import com.zzl.finance.order.service.OrderService;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : spp
 * @date : 2022/3/7 10:13
 */
@Slf4j
@RestController
@RequestMapping("order/feign")
public class FeignController extends WebBaseCtrl {

    @Autowired
    private OrderService orderService;

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存", operationId = "oo3")
    @ApidocReturnR
    public Result save(@ApidocParam(name = "保存的对象值", required = true) @RequestBody
                       @Validated OrderAddDto oOrder) {
        try {
            orderService.saveOrder(oOrder, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改订单状态
     */
    @PostMapping("/updateStatus")
    @ApidocOperation(description = "保存", operationId = "oo3")
    @ApidocReturnR
    public Result updateStatus(@ApidocParam(name = "更新", required = true) @RequestBody
                               @Validated OrderUpdateDto updateDto) {
        orderService.updateStatus(updateDto, this.getUser());
        return Result.ok();
    }
}
